package com.kingre.et.dao.jpa;

import java.util.List;

import org.apache.log4j.Logger;

import com.kingre.et.dao.IModelDAO;
import com.kingre.et.model.Model;

public class ModelDAOJPA extends GenericDAOJPA<Model, Integer> implements IModelDAO {
    private static final Logger logger = Logger.getLogger(ModelDAOJPA.class);
    
    @SuppressWarnings("unchecked")
    public Model getTdata(Integer sex, Integer grade, Integer degree, int rawValue, int vd) {
        String hql = "FROM Model WHERE ";
        hql += (sex == null ? "sex is " + sex : " sex = " + sex);
        hql += (grade == null ? " and grade is " + grade : " and grade = " + grade);
        hql += (degree == null ? " and degree is " + degree : " and degree = " + degree);
        hql += " and rawValue = ? and vd = ?";
        logger.debug("hql =" + hql);
        List<Model> model = this.getJpaTemplate().find(hql, rawValue, vd);
        logger.debug("model.size =" + model.size());
        return model.get(0);
    }

}
